package packet1;

import java.time.LocalDate;
import java.util.Date;
import java.util.Stack;

class ListNode {
      int val;
      ListNode next;
      ListNode(int x) { val = x; }
}
class Solution {
    public int[] reversePrint(ListNode head) {
        Stack<Integer> s = new Stack<>();
        while(head != null)
        {
            s.push(head.val);
            head = head.next;
        }
        int[] re = new int[s.size()];
        for(int i = 0; i < re.length; i++)
        {
            re[i] = s.pop();
            System.out.println(re[i]);
        }
        return re;
    }
}
public class hello {
    public static void main(String[] args)
    {
        Solution s = new Solution();
        ListNode n = new ListNode(1);
        n.next = new ListNode(2);
        s.reversePrint(n);
    }

}
